"""
元组

Version: 0.1
Author: yuwl
Date：2024-1-1
"""


# 定义元组
t = ('张三', 30, True, '北京')
print(t) # ('张三', 30, True, '北京')
# 获取元组中的元素
print(t[0])
print(t[3])
# 遍历
for elem in t:
	print(elem)
# 重新给元组赋值
# t[0] = '李四' # TypeError: 'tuple' object does not support item assignment
t = ('李斯', 20, True, '上海')
print(t)
# 将元组转换为列表
person = list(t)
print(person) # ['李斯', 20, True, '上海']
# 列表是可以修改它的元素的
person[0] = '王五'
person[1] = 25
print(person) # ['王五', 25, True, '上海']
# 将列表转换成元素
fruits_list = ['apple', 'banana', 'orange']
fruits_tuple = tuple(fruits_list)
print(fruits_tuple) # ('apple', 'banana', 'orange')